/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ps.packdescription.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

/**
 *
 * @author srkrishnan
 */
public class DBManager {

    private static Connection conn = null;

    public static void connectDB() {
        try {
            Configuration config = new PropertiesConfiguration("my.properties");

            String url = config.getString("db.url");
            String dbName = config.getString("db.dbname");
            String driver = config.getString("db.driver");
            String userName = config.getString("db.username");
            String password = config.getString("db.password");
            try {
                Class.forName(driver).newInstance();
                conn = DriverManager.getConnection(url + dbName + "?autoreconnect=true", userName, password);
                System.out.println("Connected to the database " + url + dbName);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (ConfigurationException ex) {
            ex.printStackTrace();
        }
    }

    public static Connection getConnection() {
        return conn;
    }
}